import AutoChart from '@/components/Echarts/AutoChart';
import { medicinenewhospital } from '@/services/api';
// @ts-ignore
import { BorderBox4 } from '@jiaminghi/data-view-react';
import React, { useEffect } from 'react';
import { useImmer } from 'use-immer';
import '../../Home.less';

const ColumnCharts: React.FC = () => {
  const [options, setOptions] = useImmer({
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "cross",
        label: {
          backgroundColor: "#6a7985",
        },
      },
    },
    grid: {
      top: '8%',
      left: '7%',
      right: '7%',
      bottom: '8%',
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        boundaryGap: false,
        data: [],
      },
    ],
    yAxis: [
      {
        type: "value",
      },
    ],
    series: [
      {
        color: "#8e9dff",
        name: "数量",
        type: "line",
        smooth: true,
        stack: "Total",
        areaStyle: {
          color: {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0.25,
                color: "#8e9dff",
              },
              {
                offset: 1,
                color: "#fff",
              },
            ],
          },
        },
        emphasis: {
          focus: "series",
        },
        data: [],
      }
    ],
  });

  useEffect(() => {
    medicinenewhospital().then((res) => {
      setOptions((draft) => {
        draft.xAxis[0].data = res.data.map(i => i.name)
        draft.series[0].data = res.data.map(i => Number(i.value))
      });
    });
  }, []);

  return (
    <div className="chart_box">
      <BorderBox4 color={['#396993', '#396993']}>
        <div className="chart_title">中医馆变化趋势</div>
        <div className="chart_chart padding-5">
          <AutoChart option={options as any}></AutoChart>
        </div>
      </BorderBox4>
    </div>
  );
};
export default ColumnCharts;
